package cn.lg.soar.general.feign;

import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.general.api.constant.ModuleConst;
import cn.lg.soar.general.api.model.BizFileDTO;
import cn.lg.soar.general.api.model.FileDigestVO;
import cn.lg.soar.general.api.model.FileVO;
import cn.lg.soar.general.api.service.IFileApi;
import cn.lg.soar.general.feign.fallback.FileApiFallbackFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 文件上传接口
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.general.client.FileApiClient")
@ApiClient
@FeignClient(
        name= ModuleConst.MODULE_NAME,
        path= ModuleConst.CLIENT_PATH + "/file",
        fallbackFactory= FileApiFallbackFactory.class,
        contextId="FileApiFeign"
)
public interface FileApiFeign extends IFileApi {

    @PostMapping("fastUpload-biz")
    @Override
    List<FileVO> fastUpload(
            @RequestParam("bizId") Long bizId,
            @RequestParam("bizType") String bizType,
            @RequestBody Collection<FileDigestVO> vos
    );

    @PostMapping("fastUpload")
    @Override
    List<FileVO> fastUpload(@RequestBody Collection<FileDigestVO> vos);

    @PostMapping("upload-biz")
    @Override
    List<FileVO> upload(@RequestParam("bizId")Long bizId, @RequestParam("bizType")String bizType, Collection<MultipartFile> files);

    @PostMapping("upload-bucket")
    @Override
    List<FileVO> upload(@RequestParam("bucketName")String bucketName, Collection<MultipartFile> files);

    @PostMapping("upload")
    @Override
    List<FileVO> upload(Collection<MultipartFile> files);

    @PostMapping("saveBizFile")
    @Override
    boolean saveBizFile(@RequestParam("bizId")Long bizId, @RequestBody Collection<BizFileDTO> bizFiles);

    @GetMapping("getBizFile")
    @Override
    Map<String, List<FileVO>> getBizFile(@RequestParam("bizId")Long bizId, @RequestParam("bizTypes")Collection<String> bizTypes);

    @PostMapping("removeBizFile")
    @Override
    boolean removeBizFile(@RequestParam("bizId")Long bizId, @RequestParam("bizTypes")Collection<String> bizTypes);


    @GetMapping("createTemporaryUrl")
    @Override
    String createTemporaryUrl(
            @RequestParam("anonymous") boolean anonymous,
            @RequestParam("fileId") long fileId,
            @RequestParam("expire") long expire,
            @RequestParam("userIds") Set<Long> userIds
    );

    @GetMapping("createFixedSecretUrl")
    @Override
    String createFixedSecretUrl(@RequestParam("fileId")long fileId);


}
